const app = getApp();
Component({
  data: {
    showAction: false,
    sortOptions: [
      { text: '时间', value: 'time' },
      { text: '按年', value: 'year' },
      { text: '按月', value: 'month' },
      { text: '名称', value: 'name' }
    ],
    selectdItem: 0,
    staffList: [
      {
        id: 1,
        avatar: '灵',
        name: '灵云ui',
        department: '技术部',
        mobile: '13865236552'
      },
    ],
    actions: [
      { name: '编辑', action: 'edit' },
      { name: '删除', color: "#ee0a24",action: 'delete' },
    ],
  },
  lifetimes: {
    attached: function () {
      this.getStaffList()
    },
  },
  methods: {
    getStaffList() {
      app.axios('user', { op: 'ajaxUserDlList' }).then(res => {
        if (res.code) {
          res.lists.forEach(item => {
            item.avatar = item.name.slice(0, 1)
          })
          this.setData({
            staffList: res.lists
          })
        }
      })
    },
    onAddStaff() {
      // 跳转到添加客户页面
      app.navigateTo('/pages/operation-center/add-staff/index');
    },
    onCall(e) {
      // 拨打电话逻辑
    },
    onStaffPress(e) {
      this.setData({
        showAction: true,
        selectdItem: e.currentTarget.dataset.item
      })
      return false
    },
    onSelect(e) {
      const id = this.data.selectdItem.id;
      this.setData({
        showAction: false,
      })
      if (e.detail.action == 'edit') {
        app.navigateTo(`/pages/operation-center/add-staff/index?id=${id}`)
      } else if (e.detail.action == 'delete') {
        const alert = this.selectComponent('#v-alert')
        alert.toggleAlert()
      }
    },
    onSelectClose(e) {
      this.setData({ showAction: false });
    },
    handleDelete() {
      const item = this.data.selectdItem
      app.axios('user', {
        op: 'ajaxUserDlDel',
        id: item.id,
        uid: item.userid
      }).then(res => {
        if (res.code) {
          wx.showToast({ title: '删除成功' })
          setTimeout(() => {
            this.getStaffList()
          }, 500);
        }
      })

    }
  }
})